package com.yz.lzq.liwushuo.ui.modules.gift.tuijian;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.yz.lzq.liwushuo.R;
import com.yz.lzq.liwushuo.jsonbean.gift.GiftTuiJianBean;
import com.yz.lzq.liwushuo.ui.webview.category.CategoryWebActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by AdminJia on 2016/11/26.
 */

public class GiftTuiJianAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<GiftTuiJianBean.DataBean.ItemsBean> mList;
    private Context mContext;

    public List<GiftTuiJianBean.DataBean.ItemsBean> getmList() {
        return mList;
    }

    private View view = null;

    public GiftTuiJianAdapter(List<GiftTuiJianBean.DataBean.ItemsBean> mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        view = LayoutInflater.from(mContext).inflate(R.layout.item_gift_vp_tuijian, null);
        return new ViewHolderData(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        GiftTuiJianBean.DataBean.ItemsBean itemsBean = mList.get(position);
        String name = itemsBean.getName();
        String short_description = itemsBean.getShort_description();
        final String url = itemsBean.getUrl();
        String price = itemsBean.getPrice();
        String cover_webp_url = itemsBean.getCover_webp_url();
        if (holder instanceof ViewHolderData) {
            ((ViewHolderData) holder).simpleDraweeViewGiftVpTuiJianRecyclerView.setImageURI(Uri
                    .parse(cover_webp_url));
            ((ViewHolderData) holder).textViewGiftVpTuiJianRecyclerViewName.setText(name);
            ((ViewHolderData) holder).textViewGiftVpTuiJianRecyclerViewPrice.setText(price);
            ((ViewHolderData) holder).textViewGiftVpTuiJianRecyclerViewDescription.setText
                    (short_description);

        }
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(mContext, CategoryWebActivity.class);
                intent.putExtra("url", url);
                mContext.startActivity(intent);

            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ViewHolderData extends RecyclerView.ViewHolder {
        @Bind(R.id.simpleDraweeView_gift_vp_tuiJian_recyclerView)
        SimpleDraweeView simpleDraweeViewGiftVpTuiJianRecyclerView;
        @Bind(R.id.textView_gift_vp_tuiJian_recyclerView_name)
        TextView textViewGiftVpTuiJianRecyclerViewName;
        @Bind(R.id.textView_gift_vp_tuiJian_recyclerView_description)
        TextView textViewGiftVpTuiJianRecyclerViewDescription;
        @Bind(R.id.textView_gift_vp_tuiJian_recyclerView_price)
        TextView textViewGiftVpTuiJianRecyclerViewPrice;

        public ViewHolderData(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
    }
    public void addItems(List<GiftTuiJianBean.DataBean.ItemsBean> _list, int positionStart) {
        mList.addAll(_list);
        int itemCount = _list.size();
        notifyItemRangeInserted(positionStart, itemCount);
    }
    public void reloadRecyclerView(List<GiftTuiJianBean.DataBean.ItemsBean> _list, boolean isClear) {
        if (isClear) {
            mList.clear();
        }
        mList.addAll(_list);
        notifyDataSetChanged();
    }


}